// pages/order/order.js
const app = getApp()
var utils = require('../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		currentPage: 1,
		orderlist:[]
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onShow: function (options) {
		this.setData({
			orderlist:[],
			currentPage:1
		})
		this.myOrderList();
	},
	myOrderList:function(e){
		var that=this;
		utils.http("/api/v1/order/my_order_list",{
			page:that.data.currentPage
		},function(res){
			var allpost = that.data.orderlist || [];
			for(var i in res.datas){
				res.datas[i].create_time = utils.formatTime(res.datas[i].create_time, "Y.M.D h:m:s")	
				allpost.push(res.datas[i])
			}
			if (res.datas.length < 10) {
				that.setData({
					tishi_title: '已加载全部',
				});
			} else {
				that.setData({
					tishi_title: '加载更多',
				});
			}
			
			that.setData({
				orderlist: allpost,
				ready: res.datas.length == 0 ? 1 : 2,
			})
			console.log(that.data.orderlist)
		})
	},
	onOrderDetailTap:function(e){
		wx.navigateTo({
			url: '../orderdetail/orderdetail?id=' + e.currentTarget.dataset.id
		})
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},


	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {
	
	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {
		var that = this;
		that.setData({
			currentPage: 1,
		})
		that.myOrderList();
		wx.stopPullDownRefresh() //停止下拉刷新
		
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		var that = this;
		if (that.data.ready == 2) {
			var page = that.data.currentPage + 1
			that.setData({
				currentPage: page,
			})
			that.myOrderList()
		}
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})